<template>
  <el-switch v-model="vValue" v-bind="attrs" @change="val => itemEvent('change', val)"></el-switch>
</template>

<script setup>
const attrs = useAttrs();
import { vModelValue } from '@/utils/hooks.js';

const props = defineProps({
  modelValue: {
    type: [String, Boolean],
    default: '',
  },
  row: {
    // form数据,或者table的行数据
    type: Object,
    default: () => ({}),
  },
});
const emits = defineEmits(['update:modelValue', 'itemEvent']);
const { newValue: key } = vModelValue(props, emits);
let vValue = ref(key);

function itemEvent(eventName, val) {
  emits('itemEvent', { eventName, prop: attrs.prop, value: val, row: props.row });
}
</script>
